/**
 * 公共配置
 */
const file = require('./utils/file')
const path = require('path')

const { entry, plugins } = file.createEnrty()
console.log(plugins)

const HtmlWebpackPlugin = require('html-webpack-plugin')

/**@type {import('webpack').Configuration} */

const config = {
  entry,
  output: {
    path: path.resolve(__dirname, '../dist'),
    chunkFilename: 'js/[name].js',
    publicPath: './',
    filename: 'js/[name].js',
    clean: true
  },
  resolve: {
    // 起别名，项目中就可以使用 @ 表示 src 目录了
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },

  module: {
    rules: [
      // { test: /\.vue$/, use: 'vue-loader' },
      { test: /\.css$/, use: ['style-loader', 'css-loader'] },
      {
        test: /.(png|jpg|jpeg|svg|gif)$/i,
        type: 'asset/resource'
      },
      {
        test: /.(woff|woff2|eot|ttf|otf)$/i,
        type: 'asset/resource'
      }
    ]
  },
  plugins: []
}

// 处理多页面 html 模板
plugins.forEach(plugin => {
  config.plugins.push(new HtmlWebpackPlugin(plugin))
})
module.exports = config
